; *** Tafl
; *** Copyright 1998-2002 Zillions Development
; v.2.0

; You need to purchase Zillions of Games to load this rules file
; Visit the Zillions web site at http://www.zillions-of-games.com
(translate
 ("Green" "攻方") ("Red" "守方")
 ("Rook" "车") ("King" "王")
 ("Brandubh" "爱尔兰板棋 Brandubh")("Ard-Ri" "苏格兰板棋 Ard-Ri")
 ("Fitchneal" "凯尔特板棋 Fitchneal")("Tablut" "芬兰板棋 Tablut")
 ("Tawlbrydd" "威尔士板棋 Tawlbrydd")("Tawlbrydd II" "威尔士板棋二 Tawlbrydd II")
 ("Small Hnefatafl" "小挪威板棋 Small Hnefatafl")("Large Hnefatafl" "大挪威板棋 Large Hnefatafl")
 ("Alea Evangeli" "英格兰板棋 Alea Evangeli")
)

; Could optimize move generation
;   Define green rooks differently-Red rooks and Red kings don't check for sandwiching the King

; INPUTS: $1 == direction you're looking at
;         $2 == a sideways direction from $2
; Check in this direction for a capture
(define check-direction
    (if (enemy? $1) ; Is there an enemy this direction?
       $1
       (if (piece? Rook) 
	      (if (or (friend? $1)            (in-zone? Konakis $1))		
		       capture
	      )
        else ; piece? King
          (if (and (or (not-on-board? $1)            (friend? $1)            (in-zone? Konakis $1))
                   (or (not-on-board? $2)            (friend? $2)            (in-zone? Konakis $2))
                   (or (not-on-board? (opposite $2)) (friend? (opposite $2)) (in-zone? Konakis (opposite $2)))
              )
              capture
          )
	   )
       (opposite $1)
	)
)


; INPUTS: $1 == direction you're moving
;         $2 == a sideways direction from $1
;         $3 == a sideways direction from $1, i.e. (opposite $2)
; Add all rook moves
(define rook-slide
   (
    $1
     (while empty?
        (if (not-in-zone? Konakis)
           (check-direction $2 $1)
           (check-direction $3 $1)
           (check-direction $1 $2)
           add
        )
        $1 ; Move to next
     )
   )
)

(define king-slide
   (
    $1
     (while empty?
           (check-direction $2 $1)
           (check-direction $3 $1)
           (check-direction $1 $2)
           add
        $1 ; Move to next
     )
   )
)


;******************************************************************
(game
   (title "Brandubh")
   (description "板棋(Tafl)是一种攻守型的棋类游戏。绿方的目标是杀死红王，红方的目标是跑到棋盘上标记有王的逃脱地点。\\
	   所有的棋子移动模式均和车相同，即横直走不限格数。
	   吃子需要把目标子横向或纵向夹在两个自己子中间吃掉，即“夹吃”。
	   吃王则需要四方围住，即“围吃”。当王处于边角，或与王宫相邻时，需要围的方向相应减少。\\
	   棋盘中间的粉色格子即为王座。只有王才可落于王座内，其他棋子只能走过，不能落在上面。王座的另一个作用是可以视为任一方的棋子来“夹吃”或“围吃”另一方棋子。\\
	   除英格兰板棋是红方先走之外，均为绿方先走。")
   (history "Tafl had a rich history in Viking tales.  In one such story
       King Knut and Jarl Ulf were playing and Knut made mistake allowing
	   Ulf to capture a piece.  Knut requested that he be allowed to take back
	   his move.  Ulf refused, toppling the board, and an argument ensued that
	   ended when Ulf was killed.\\
	   The Swedish botanist Carolus Linnaeus, who invented the original system for
	   classifying plants and animals we still use today, wrote about this game
	   in his diary in 1732.  The side with the King represented
       the Swedes, while the other side respresented Muscovites.\\
	   These variations are provided on different sized boards:\
	   Brandubh -- Irish\
	   Fitchneal -- Irish  (Gwyddbwyll -- Scottish)\
	   Ard-Ri (`High King`) - Scottish\
	   Tablut -- Finish/Scandinavian\
	   Tawlbrydd -- Welsh\
	   Hnefatafl - Norse\
	   Alea Evangeli -- Anglo Saxon")
   (strategy "Be wary whenever one of your pieces is orthogonal adjacent to an
	   opponent's as it's liable to get captured.  Trading early in the
	   game generally helps Red rather than Green, because Red needs open space
	   to escape with his King.  Green should try to keep everything blocked
	   and crowd the King in.\\
	   Both sides should look for King moves that leave the King
	   with two different clear paths to the perimeter, since it will be
	   impossible to block both at the same time.")      
   (option "prevent flipping" 2)
   (players Red Green)
   (turn-order Green Red)

   (piece
      (name Rook)
      (image Red "images\Tafl\RedRook_big.bmp" "images\Tafl\RedRook.bmp"
             Green "images\Tafl\GreenRook_big.bmp" "images\Tafl\GreenRook.bmp")
	  (help "车：横直走，不限格数，夹吃")  
      (description "车\横直走，不限格数。不能越子。不可进入王座。\\
		   吃车需要使其两个相反方向均被敌方或王座包围，即“夹吃”。")
      (moves
         (rook-slide n e w)
         (rook-slide e n s)
         (rook-slide s e w)
         (rook-slide w n s)
      )
   )

   (piece
      (name King)
      (image Red "images\Tafl\RedKing_big.bmp" "images\Tafl\RedKing.bmp")
	  (help "王：横直走，不限格数，夹吃")
      (description "王\横直走，不限格数。不能越子。可进入王座。\\
		   吃王需要使其四个方向均被敌方包围，即“围吃”。")
      (moves
         (king-slide n e w)
         (king-slide e n s)
         (king-slide s e w)
         (king-slide w n s)
      )
   )

   (board
        (image "images\Tafl\Brandubh_big.bmp" "images\Tafl\Brandubh.bmp")
        (grid
            (start-rectangle 6 6 50 50)
            (dimensions
		        ("a/b/c/d/e/f/g" (44 0)) ; columns
		        ("7/6/5/4/3/2/1" (0 44)) ; rows
            )
            (directions (n 0 -1) (e 1 0) (s 0 1) (w -1 0))
        )
        (zone
           (name goals)
           (players Red)
           (positions a1 a7 g1 g7)
        )
        (zone
           (name Konakis)
           (players Red Green)
           (positions d4 a1 a7 g1 g7)
        )
   )
   (board-setup
      (Red
         (Rook c4 d3 d5 e4)
         (King d4)
      )
      (Green
         (Rook a3 a5 c1 c7 e1 e7 g3 g5)
      )
   )

   (win-condition (Red) (absolute-config King (goals)))
   (loss-condition (Red) (pieces-remaining 0 King))
)


(variant
   (title "Ard-Ri")
   (board-setup
      (Red
         (Rook c3 c4 c5 d3 d5 e3 e4 e5)
         (King d4)
      )
      (Green
         (Rook a3 a4 a5 b4 c1 c7 d1 d2 d6 d7 e1 e7 f4 g3 g4 g5)
      )
   )
)

(variant
   (title "Fitchneal")
   (board
        (image "images\Tafl\Fitchneal_big.bmp" "images\Tafl\Fitchneal.bmp")
        (grid
            (start-rectangle 6 6 50 50)
            (dimensions
		        ("a/b/c/d/e/f/g" (44 0)) ; columns
		        ("7/6/5/4/3/2/1" (0 44)) ; rows
            )
            (directions (n 0 -1) (e 1 0) (s 0 1) (w -1 0))
        )
        (zone
           (name goals)
           (players Red)
           (positions a1 a2 a3 a4 a5 a6 a7
                      g1 g2 g3 g4 g5 g6 g7
                      b1 c1 d1 e1 f1
                      b7 c7 d7 e7 f7
           )
        )
        (zone
           (name Konakis)
           (players Red Green)
           (positions d4)
        )
   )
   (board-setup
      (Red
         (Rook b4 c4 d2 d3 d5 d6 e4 f4)
         (King d4)
      )
      (Green
         (Rook a1 a3 a4 a5 a7 c1 c7 d1 d7 e1 e7 g1 g3 g4 g5 g7)
      )
   )
)

;******************************************************************
(variant (title "-")) ; -------------------------------------------

(variant
   (title "Tablut")
   (board
        (image "images\Tafl\Tablut_big.bmp" "images\Tafl\Tablut.bmp")
        (grid
            (start-rectangle 7 7 46 46)
            (dimensions
		        ("a/b/c/d/e/f/g/h/i" (44 0)) ; columns
		        ("9/8/7/6/5/4/3/2/1" (0 44)) ; rows
            )
            (directions (n 0 -1) (e 1 0) (s 0 1) (w -1 0))
        )
        (zone
           (name goals)
           (players Red)
           (positions i1 i9 a1 a9)
        )
        (zone
           (name Konakis)
           (players Red Green)
           (positions e5 i1 i9 a1 a9)
        )
   )
   (board-setup
      (Red
         (Rook e4 e3 d5 c5 e6 e7 f5 g5)
         (King e5)
      )
      (Green
         (Rook a4 a5 a6 i4 i5 i6 d1 e1 f1 d9 e9 f9 e2 b5 h5 e8)
      )
   )
)


;******************************************************************
(variant (title "-")) ; -------------------------------------------

(define Tawlbrydd-board
   (board
        (image "images\Tafl\Tawlbrydd_big.bmp" "images\Tafl\Tawlbrydd.bmp")
        (grid
            (start-rectangle 6 6 50 50)
            (dimensions
		        ("a/b/c/d/e/f/g/h/i/j/k" (44 0)) ; columns
		        ("11/10/9/8/7/6/5/4/3/2/1" (0 44)) ; rows
            )
            (directions (n 0 -1) (e 1 0) (s 0 1) (w -1 0))
         )
        (zone
           (name goals)
           (players Red)
           (positions a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11
                      k1 k2 k3 k4 k5 k6 k7 k8 k9 k10 k11
                      b1 c1 d1 e1 f1 g1 h1 i1 j1
                      b11 c11 d11 e11 f11 g11 h11 i11 j11
           )
         )
        (zone
           (name Konakis)
           (players Red Green)
           (positions f6)
         )
   )
)
(variant 
   (title "Tawlbrydd")
   (Tawlbrydd-board)
   (board-setup
      (Red
         (Rook c6 d6 e6 f3 f4 f5 f7 f8 f9 g6 h6 i6)
         (King f6)
      )
      (Green
         (Rook a4 a5 a6 a7 a8 b6
               k4 k5 k6 k7 k8 j6
               d1 e1 f1 g1 h1 f2
               d11 e11 f11 g11 h11 f10
         )
      )
   )
)
(variant 
   (title "威尔士板棋二 Tawlbrydd II")
   (Tawlbrydd-board)
   (board-setup
      (Red
         (Rook d6 e5 e6 e7 f4 f5 f7 f8 g5 g6 g7 h6)
         (King f6)
      )
      (Green
         (Rook a5 a6 a7 b5 b7 c6
               k5 k6 k7 j5 j7 i6
               e1 f1 g1 e2 g2 f3
               e11 f11 g11 e10 g10 f9
         )
      )
   )
)
(variant 
   (title "小挪威板棋 Small Hnefatafl")
   (Tawlbrydd-board)
   (board-setup
      (Red
         (Rook d6 e5 e6 e7 f4 f5 f7 f8 g5 g6 g7 h6)
         (King f6)
      )
      (Green
         (Rook a4 a5 a6 a7 a8 b6
               k4 k5 k6 k7 k8 j6
               d1 e1 f1 g1 h1 f2
               d11 e11 f11 g11 h11 f10
         )
      )
   )
)

;******************************************************************
(variant (title "-")) ; -------------------------------------------

(variant
   (title "大挪威板棋 Large Hnefatafl")
   (board
        (image "images\Tafl\LgHnefatafl.bmp")
        (grid
            (start-rectangle 3 3 25 25)
            (dimensions
		        ("a/b/c/d/e/f/g/h/i/j/k/l/m" (22 0)) ; columns
		        ("13/12/11/10/9/8/7/6/5/4/3/2/1" (0 22)) ; rows
            )
            (directions (n 0 -1) (e 1 0) (s 0 1) (w -1 0))
         )
        (zone
           (name goals)
           (players Red)
           (positions a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13
                      m1 m2 m3 m4 m5 m6 m7 m8 m9 m10 m11 m12 m13
                      b1 c1 d1 e1 f1 g1 h1 i1 j1 k1 l1
                      b13 c13 d13 e13 f13 g13 h13 i13 j13 k13 l13
           )
         )
        (zone
           (name Konakis)
           (players Red Green)
           (positions g7)
         )
   )
   (board-setup
      (Red
         (Rook d7 e7 f7  h7 i7 j7
		       g4 g5 g6  g8 g9 g10)
         (King g7)
      )
      (Green
         (Rook a5 a6 a7 a8 a9 b7
		       e1 f1 g1 h1 i1 g2
			   e13 f13 g13 h13 i13 g12
			   m5 m6 m7 m8 m9 l7)
      )
   )
   (piece
      (name Rook)
      (image Red "images\Tafl\RedRook.bmp" Green "images\Tafl\GreenRook.bmp")
	  (help "车：横直走，不限格数，夹吃")  
      (description "车\横直走，不限格数。不能越子。不可进入王座。\\
		   吃车需要使其两个相反方向均被敌方或王座包围，即“夹吃”。")
      (moves
         (rook-slide n e w)
         (rook-slide e n s)
         (rook-slide s e w)
         (rook-slide w n s)
      )
   )

   (piece
      (name King)
      (image Red "images\Tafl\RedKing.bmp")
	  (help "王：横直走，不限格数，夹吃")
      (description "王\横直走，不限格数。不能越子。可进入王座。\\
		   吃王需要使其四个方向均被敌方包围，即“围吃”。")
      (moves
         (king-slide n e w)
         (king-slide e n s)
         (king-slide s e w)
         (king-slide w n s)
      )
   )
)

;******************************************************************
(variant (title "-")) ; -------------------------------------------

(variant
   (title "英格兰板棋 Alea Evangeli")
   (turn-order Red Green)
   (board
        (image "images\Tafl\AleaEvangeli.bmp")
        (grid
            (start-rectangle 3 3 23 23)
            (dimensions
		        ("a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s" (22 0)) ; columns
		        ("19/18/17/16/15/14/13/12/11/10/9/8/7/6/5/4/3/2/1" (0 22)) ; rows
            )
            (directions (n 0 -1) (e 1 0) (s 0 1) (w -1 0))
         )
        (zone
           (name goals)
           (players Red)
           (positions a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19
                      s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12 s13 s14 s15 s16 s17 s18 s19
                      b1 c1 d1 e1 f1 g1 h1 i1 j1 k1 l1 m1 n1 o1 p1 q1 r1
                      b19 c19 d19 e19 f19 g19 h19 i19 j19 k19 l19 m19 n19 o19 p19 q19 r19
           )
         )
         (zone
           (name Konakis)
           (players Red Green)
           (positions j10)
         )
  )
   (board-setup
      (Red
         (Rook i15 k15
               j13
               i12 k12
               e11 h11 j11 l11 o11
               g10 i10 k10 m10
               e9 h9 j9 l9 o9
               i8 k8
               j7
               i5 k5)
         (King j10)
      )
      (Green
         (Rook c19 f19 n19 q19
               a17 f17 n17 s17
               h16 j16 l16
               g15 m15
               a14 c14 f14 n14 q14 s14
               e13 o13
               d12 p12
               d10 p10
               d8 p8
               e7 o7
               a6 c6 f6 n6 q6 s6
               g5 m5
               h4 j4 l4
               a3 f3 n3 s3
               c1 f1 n1 q1)
      )
   )
   (piece
      (name Rook)
      (image Red "images\Tafl\RedRook.bmp" Green "images\Tafl\GreenRook.bmp")
      (help "车：横直走，不限格数，夹吃")  
      (description "车\横直走，不限格数。不能越子。不可进入王座。\\
		   吃车需要使其两个相反方向均被敌方或王座包围，即“夹吃”。")
      (moves
         (rook-slide n e w)
         (rook-slide e n s)
         (rook-slide s e w)
         (rook-slide w n s)
      )
   )

   (piece
      (name King)
      (image Red "images\Tafl\RedKing.bmp")
	  (help "王：横直走，不限格数，夹吃")
      (description "王\横直走，不限格数。不能越子。可进入王座。\\
		   吃王需要使其四个方向均被敌方包围，即“围吃”。")
      (moves
         (king-slide n e w)
         (king-slide e n s)
         (king-slide s e w)
         (king-slide w n s)
      )
   )
)
